#include <iostream>
#include <algorithm>
using namespace std;
int S[100002];
int K,N;
int coin[16];
int dp[1<<16];
int main()
{
	cin>>K>>N;
	int ans=-1;
	for(int i=0; i<K; i++) 	cin>>coin[i];
	for(int i=1; i<=N; i++)
	{
		int temp;
		cin>>temp;
		S[i]=S[i-1]+temp;
	}
	for(int state=0; state<=((1<<K)-1); state++)
	{
		if(dp[state]==N+1)
		{
			//cout<<endl<<state<<endl;
			int sum=0;	//不知为何要初值。
			for(int chosen=0; chosen<K; chosen++)
			{
				//cout<<((1<<chosen)&state)<<endl;
				sum+=((((1<<chosen)&state)==0)?coin[chosen]:0);
			}
			//cout<<sum;
			ans=max(ans,sum);
			continue;
		}
		for(int chosen=0; chosen<K; chosen++)
		{
			//cout<<(1<<chosen)<<" "<<state<<" "<<((1<<chosen)&state)<<endl;
			if(((1<<chosen)&state)==0)
			{
				dp[(1<<chosen)|state]=max(dp[(1<<chosen)|state],(int)(upper_bound(S+dp[state],S+N+1,coin[chosen]+S[dp[state]-1])-S));
			//	cout<<((1<<chosen)|state)<<":"<<dp[(1<<chosen)|state]<<endl;
			}
		}
	}
//	for(int state=0; state<=((1<<K)-1); state++)
//	{
//		cout<<state<<" "<<dp[state]<<endl;
//	}
	cout<<ans<<endl;
	return 0;
}